package com.ygsoft.tianlu_mall.controller;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ygsoft.tianlu_mall.pojo.Evaluation;
import com.ygsoft.tianlu_mall.pojo.Msg;
import com.ygsoft.tianlu_mall.pojo.EvaluationVO;
import com.ygsoft.tianlu_mall.service.EvaluationService;
import com.ygsoft.tianlu_mall.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;

@Controller
@RequestMapping("eva")
public class evaluationController {
    @Autowired
    EvaluationService evaluationService;
    @Autowired
    OrderService orderService;
    //查询个人所有评价
    @RequestMapping(value = "/Evaluations",method = RequestMethod.GET)
    @ResponseBody
    public Msg getEvaluationsById(
            @RequestParam(value = "evaluation_userid") int evaluation_userid,
            @RequestParam(value = "pn",defaultValue = "1")Integer pn,
            @RequestParam(value = "pageSize") Integer pageSize) {
        PageHelper.startPage(pn,pageSize);
        List<EvaluationVO> evaluationVO = evaluationService.getEvaluationVOById(evaluation_userid);
//        List<Evaluation> evaluations = evaluationService.getEvaluationsById(evaluation_userid);
        PageInfo page = new PageInfo(evaluationVO,5);
        return  Msg.succes().add("pageInfo",page);
    }
    //查看评价详情
    @RequestMapping(value = "/EvaluationDetail",method = RequestMethod.GET)
    @ResponseBody
    public Msg getEvaluationsDetail(
            @RequestParam(value = "evaluation_id") int evaluation_id) {
        List<Evaluation> evaluations = evaluationService.getEvaluationsDetail(evaluation_id);
        return Msg.succes().add("List",evaluations);
    }
    //查看评价详情By order_code
    @RequestMapping(value = "/EvaluationDetailByOrder",method = RequestMethod.GET)
    @ResponseBody
    public Msg getEvaluationsDetailByOrder(
            @RequestParam(value = "order_id") int order_id) {
        List<Evaluation> evaluations = evaluationService.getEvaluationsDetailByOrder(order_id);
        String order_code = orderService.getOrderCode(order_id);
        HashMap<String,Object> result = new HashMap<>();
        result.put("evaluations",evaluations);
        result.put("order_code",order_code);
        return Msg.succes().add("Detail",result);
    }


}
